package org.jincheng.ch06;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Jane
 * @date 2024-11-27 11:42
 */

public class DemoAddress {

    @Test
    public void getAddress() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
//        Address addr =new Address();
//        addr.setId(1);
//        addr.setUserName("张三");
//        addr.setUserId(999);
//        addr.setPostalCode("423000");
//        addr.setTelNumber("13512341234");
//        addr.setFulllocation("广东省深圳市南山区");
//
//        String location = addr.getFulllocation();
//        System.out.println(location);
        Class cls= Address.class;
//        Method[] declaredMethods = cls.getDeclaredMethods();
        Object o = cls.newInstance();
        Object o2 = cls.newInstance();
        //通过反射获取方法
        Method setTelNumber = cls.getMethod("SetTelNumber", String.class);
        setTelNumber.invoke(o,"13512341234");
        System.out.println(o);



        Method getTelNumber = cls.getMethod("GetTelNumber");
        Object num = getTelNumber.invoke(o2);
        System.out.println(num);

//        System.out.println(addr);
    }
}
